package com.wc.算法提高课.F第六章_基础算法.排序.七夕祭;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/2 10:48
 * @description https://www.acwing.com/problem/content/107/
 */
public class Main {
    /**
     * 思路：
     * 在每一行或者每一列转换时候，不影响那一行与那一列的总数
     * 并且改变时候只影响两列或者两行+1 -1的过程
     * 那就可以简化为纸牌游戏
     * 要求全部相等，说明会等于他的平均值
     * 假设平均值为 a = (/sum_1^n ai) / n
     * xi 表示移动ai -> ai+1移动了多少个
     * ai -> ai+1 xi, an -> ai xn
     * ai - xi + xi-1 = a
     * x1 = x1
     * x2 = x1 - (a1 - a)
     * x3 = x1 - (a1 + a2 - 2 * a)
     * ...
     * xn = x1 - (a1 + a2 + ... + an - (n - 1) * a)
     * x1 = x1 - C1
     * x2 = x1 - C2
     * ...
     * <p>
     * xn = x1 - Cn
     * res
     * = |x1| + |x2| + |x3| + ... + |xn|
     * = |x1 - C1| + |x1 - C2| + ... + |x1 - Cn|
     * 相当于要求min(res), 那么等于一个数轴上距离x1这个点的n个距离之和的最小值
     * 那一定是C1,C2, ... ,Cn的中间的值是最小的, 就是答案
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] cols = new int[N], rows = new int[N], sum = new int[N], c = new int[N];
    static int n, m, cnt;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        cnt = sc.nextInt();
        while (cnt-- > 0) {
            int x = sc.nextInt(), y = sc.nextInt();
            rows[x]++;
            cols[y]++;
        }
        long r = work(n, rows), c = work(m, cols);
        if (r != -1 && c != -1) out.printf("both %d\n", r + c);
        else if (r != -1) out.printf("row %d\n", r);
        else if (c != -1) out.printf("column %d\n", c);
        else out.println("impossible");
        out.flush();
    }

    static long work(int n, int[] a) {
        for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
        if (sum[n] % n != 0) return -1;
        int avg = sum[n] / n;
        c[1] = 0;
        for (int i = 2; i <= n; i++) c[i] = sum[i - 1] - (i - 1) * avg;
        Arrays.sort(c, 1, n + 1);
        long res = 0;
        for (int i = 1; i <= n; i++) res += Math.abs(c[i] - c[(n + 1) / 2]);
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
